//#define TRACE_PATHS

using RayDen.RayEngine.Core;
using RayDen.RayEngine.Core.Types;

//KelemenMLTPath;//MCMCPathTracerPath;//
namespace RayDen.RayEngine.Engines.MCMC
{

    
    public class MCMCPathBuffer : PathBuffer<MCPTPath>
    {

        public MCMCPathBuffer() { }

        public MCMCPathBuffer(int maxPaths, RayEngineScene scene, ImageFilmBase agg, SamplingContext sc)
            : base(maxPaths, scene, agg, sc)
        {
        }
        /*
        protected override void OnSplat( PathSamplerBase item )
        {
            var path = (MCMCPathTracerPath)item;
            base.OnSplat(item);
        }
         */
 
        protected static void Print(string msg)
        {
#if VERBOSE
            RayDen.Library.Components.SystemComponents.Tracer.TraceLine(msg);
#endif

        }

        public override void AdvancePaths( RayBuffer rayBuffer )
        {
            base.AdvancePaths(rayBuffer);
#if TRACE_PATHS
            Print("--------------");
            Print(string.Format("{0} samplers in LargeStep",
                this.paths.Cast<PathSampler>().Count(item => item.SamplerState == MCMCSamplerState.LargeStep)));
            Print(string.Format("{0} samplers in SmallStep",
                this.paths.Cast<PathSampler>().Count(item => item.SamplerState == MCMCSamplerState.SmallStep)));
            Print(string.Format("{0} average rejection",
                this.paths.Cast<PathSampler>().Average(item => item.rejectCount)));
            Print(string.Format("{0} Total Samples",this.paths.Count));
            Print("Importance ready : " + (Sampler as MCMCSampler).ImportanceReady);
            Print("--------------");
            
#endif
        }
        protected override PathSamplerBase CreatePathSampler()
        {
            return new MCPTPath() { SurfaceSampler = this.surfaceSampler, pathIntegrator = this, LightSampler = this.lightSampler };
        }

    }
}